{
LANG : PASCAL
PROB : transform
}

program TRANSFORM;
const
  fi = 'transform.in';
  fo = 'transform.out';
  max = 10;
type
  table = array[1..max, 1..max] of char;
var
  s, f : table;
  n : integer;

procedure inp;
var
  i, j : integer;
begin
  readln(n);
  for i := 1 to n do
  begin
    for j := 1 to n do read(s[i, j]);
    readln;
  end;
  for i := 1 to n do
  begin
    for j := 1 to n do read(f[i, j]);
    readln;
  end;
end;

function same(x, y : table) : boolean;
var
  i, j : integer;
begin
  same := false;
  for i := 1 to n do
    for j := 1 to n do
      if x[i, j] <> y[i, j] then exit;
  same := true;
end;

procedure rot(var x : table);
var
  i, j, i1, j1 : integer;
  temp : table;
begin
  temp := x;
  j1 := 1;
  for i := 1 to n do
  begin
    i1 := n;
    for j := 1 to n do
    begin
      x[i, j] := temp[i1, j1];
      dec(i1);
    end;
    inc(j1);
  end;
end;

procedure ref(var x : table);
var
  i, j, i1, j1 : integer;
  temp : table;
begin
  temp := x;
  i1 := 1;
  for i := 1 to n do
  begin
    j1 := n;
    for j := 1 to n do
    begin
      x[i, j] := temp[i1, j1];
      dec(j1);
    end;
    inc(i1);
  end;
end;

procedure out(k : integer);
begin
  assign(output, fo); rewrite(output);
  writeln(k);
  close(output);
  halt;
end;

procedure process;
var
  temp : table;
begin
  temp := s;
  rot(temp);
  if same(temp, f) then out(1);
  rot(temp);
  if same(temp, f) then out(2);
  rot(temp);
  if same(temp, f) then out(3);
  temp := s;
  ref(temp);
  if same(temp, f) then out(4);
  rot(temp);
  if same(temp, f) then out(5);
  rot(temp);
  if same(temp, f) then out(5);
  rot(temp);
  if same(temp, f) then out(5);
  temp := s;
  if same(temp, f) then out(6);
  out(7);
end;

begin
  assign(input, fi); reset(input);
  inp;
  process;
  close(input);
end.